package com.jz.storeroomclass.conroller;

//import com.jz.subclass.test.SubStatusEnum;

import com.jz.storeroomclass.model.StoreroomAddVo;
import com.jz.storeroomclass.model.StoreroomSelectVo;
import com.jz.storeroomclass.model.StoreroomUpdateStatusVo;
import com.jz.storeroomclass.model.StoreroomUpdateVo;
import com.jz.storeroomclass.service.StoreroomService;
import com.jz.util.ResultBuildVo;
import com.jz.util.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * Created by WISE on 2021/12/26.
 */
@RestController
@CrossOrigin//开启跨域
public class StoreroomController {


    //1.首页分页
    @Autowired
    private StoreroomService storeroomService;

    @PostMapping("warehouse/queryPage")
    public ResultVo firstPage(@RequestBody StoreroomSelectVo storeroomSelectVo) {
        ResultVo resultVo = storeroomService.firstPage(storeroomSelectVo);

        return resultVo;
    }

    //2.新增
    @PostMapping("warehouse/add")
    @Transactional
    public ResultVo add(@RequestBody @Valid StoreroomAddVo partAddVO, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultBuildVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        ResultVo resultVo = storeroomService.addpartClass(partAddVO);
        return resultVo;
    }

   @PostMapping("warehouse/update")
    public ResultVo update(@RequestBody @Valid StoreroomUpdateVo partUpdateVo, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultBuildVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
       return storeroomService.updateSubClass(partUpdateVo);
   }

    @PostMapping("warehouse/updateStatus")
    public ResultVo updateStatus(@RequestBody @Valid StoreroomUpdateStatusVo partUpdateStatusVo, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultBuildVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return storeroomService.updateStatus(partUpdateStatusVo);
    }
    @GetMapping("warehouse/area")
    public ResultVo area() {

        return storeroomService.area();
    }
    @GetMapping("warehouse/nation")
    public ResultVo nation(Integer id) {

        return storeroomService.nation(id);
    }
    @GetMapping("warehouse/province")
    public ResultVo province(Integer id) {

        return storeroomService.province(id);
    }
    @GetMapping("warehouse/city")
    public ResultVo city(Integer id) {

        return storeroomService.city(id);
    }
    @GetMapping("warehouse/county")
    public ResultVo county(Integer id) {

        return storeroomService.county(id);
    }


}



